package repository

import (
	"group-chat/initialize"
	"group-chat/model"
)

func LoginUser(mobile string, password string) (user model.User, err error) {
	err = initialize.DB.Where("mobile=?", mobile).Where("password=?", password).Find(&user).Error
	if err != nil {
		return model.User{}, err
	}
	return user, err
}

func AddArticle(title string, author int, counter string, t int) (article model.Article, err error) {
	article = model.Article{
		Title:   title,
		Author:  author,
		Counter: counter,
		Type:    t,
	}
	err = initialize.DB.Create(&article).Error
	if err != nil {
		return model.Article{}, err
	}
	return article, nil
}
